package cn.wyj.config;

import cn.wyj.dao.StatisticMapper;
import cn.wyj.utils.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务管理
 */
@Component
public class ScheduleTask {

    @Autowired
    private StatisticMapper statisticMapper;

    @Autowired
    private MailUtils mailUtils;

//    @Scheduled(cron = "0,15,30,45 * * * * *")
    @Scheduled(cron = "0 0 12 * * ?")
    public void sendMail(){
        long totalHits = statisticMapper.getTotalHits();
        long totalComments = statisticMapper.getTotalComments();
        StringBuffer content = new StringBuffer();
        content.append("博客系统总访问量："+totalHits+"人\n");
        content.append("博客系统总评论量："+totalComments+"条\n");
        mailUtils.sendSimpleMail("1556802726@qq.com","博客统计情况",content.toString());
        System.out.println("邮件发送成功");
    }
}
